<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\LoginModel;

class LoginController extends Controller
{/**
 * 登录页面
 */
    public function login(){
    	return view('admin/login');

    }

    //执行登录
    public function loginDo(Request $request){
        
        $data=request()->except("_token");

        $data['user_pwd']=sha1($data['user_pwd']);
    	
        //dd($data);
    	$res=LoginModel::where($data)->first();
        //dd($res);
    	if($res){
    		session(['user'=>$res]);
    		 echo "<script>alert('登陆成功!');location='/admin/index'</script>";
    	}else{
    		echo "<script>alert('账号或密码错误!');location='/admin/login'</script>";
    	}

    }
    
}
